/// @tags: DivBlock
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>

using namespace std;

namespace BlueQuantum {

typedef long long ll;

int const N = 1e5 + 5e4 + 5, B = 387;

int n, m, b_cnt;
int len[N], sum[N], bel[N], ord[N], sumlen[N], a[N], b[N], hash[N], tag[B], L[B], R[B];
ll ans;

struct Query {
  int x, y;
} q[N];

inline bool cmp(int a, int b) { return sum[a] < sum[b]; }

inline void rebuild(int x) {
  sort(ord + L[x], ord + R[x] + 1, cmp);
  sumlen[L[x]] = len[ord[L[x]]];
  for (int i = L[x] + 1; i <= R[x]; ++i) sumlen[i] = sumlen[i - 1] + len[ord[i]];
}

inline void prework() {
  for (int i = 1; i <= n; ++i) sum[a[i]]++, sum[b[i]]--;
  for (int i = 1; i <= *hash; ++i) {
    if (i < *hash) len[i] = hash[i + 1] - hash[i];
    sum[i] += sum[i - 1], ans += (ll)abs(sum[i]) * len[i];
  }
  b_cnt = *hash / B;
  for (int i = 1; i <= b_cnt; ++i) L[i] = R[i - 1] + 1, R[i] = L[i] + B - 1;
  R[b_cnt] = *hash;
  for (int i = 1; i <= b_cnt; ++i)
    for (int j = L[i]; j <= R[i]; ++j) bel[j] = i, ord[j] = j;
  for (int i = 1; i <= b_cnt; ++i) rebuild(i);
}

inline void add(int x) {
  for (int i = x; i <= R[bel[x]]; ++i)
    ans += (ll)len[i] * (sum[i]++ + tag[bel[x]] >= 0 ? 1 : -1);
  rebuild(bel[x]);
  for (int i = bel[x] + 1; i <= b_cnt; ++i) {
    int l = L[i], r = R[i], res = -1, mid;
    while (l <= r) {
      mid = (l + r) >> 1;
      if (sum[ord[mid]] + tag[i] >= 0) res = mid, r = mid - 1;
      else
        l = mid + 1;
    }
    if (res == -1) ans -= sumlen[R[i]];
    else if (res == L[i])
      ans += sumlen[R[i]];
    else {
      ans -= sumlen[res - 1];
      ans += sumlen[R[i]] - sumlen[res - 1];
    }
    tag[i]++;
  }
}

inline void sub(int x) {
  for (int i = x; i <= R[bel[x]]; ++i)
    ans += 1ll * len[i] * (sum[i]-- + tag[bel[x]] <= 0 ? 1 : -1);
  rebuild(bel[x]);
  for (int i = bel[x] + 1; i <= b_cnt; ++i) {
    int l = L[i], r = R[i], res = -1, mid;
    while (l <= r) {
      mid = (l + r) >> 1;
      if (sum[ord[mid]] + tag[i] <= 0) res = mid, l = mid + 1;
      else
        r = mid - 1;
    }
    if (res == -1) ans -= sumlen[R[i]];
    else if (res == R[i])
      ans += sumlen[R[i]];
    else {
      ans += sumlen[res];
      ans -= sumlen[R[i]] - sumlen[res];
    }
    tag[i]--;
  }
}

inline int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> a[i], hash[++*hash] = a[i];
  for (int i = 1; i <= n; ++i) cin >> b[i], hash[++*hash] = b[i];
  cin >> m;
  for (int i = 1; i <= m; ++i) cin >> q[i].x >> q[i].y, hash[++*hash] = q[i].y;
  sort(hash + 1, hash + *hash + 1);
  *hash = unique(hash + 1, hash + *hash + 1) - hash - 1;
  for (int i = 1; i <= n; ++i)
    a[i] = lower_bound(hash + 1, hash + *hash + 1, a[i]) - hash,
    b[i] = lower_bound(hash + 1, hash + *hash + 1, b[i]) - hash;
  for (int i = 1; i <= m; ++i)
    q[i].y = lower_bound(hash + 1, hash + *hash + 1, q[i].y) - hash;
  prework();
  cout << ans << '\n';
  for (int i = 1; i <= m; ++i) {
    sub(a[q[i].x]), add(a[q[i].x] = q[i].y);
    cout << ans << '\n';
  }
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("P3992 [BJOI2017] 开车.in", "r", stdin);
  freopen("P3992 [BJOI2017] 开车.out", "w", stdout);
#endif
#endif

  ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
